package com.wxf.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getSession().invalidate();
        resp.setContentType("text/html;charset=utf-8");
        // 因为是用框架写的页面，只用resp.sendRedirect()的方法无法使整个页面回到login.jsp，
        // 要用top.location.href='login.jsp'的方法才行
        resp.getWriter().println("<script>top.location.href='login.jsp'</script>");
    }
}
